# -*- coding: utf-8 -*-

import xml.etree.cElementTree as etree

class config():
    settings = {}

    def __init__(self, configFile):
        for event, node in etree.iterparse(configFile):
            if not ((node.tag == u"Config") or (node.tag == u"Scintilla") or (node.tag == u"GUI")):
                if node.text == u"True":
                    self.settings[node.tag] = True
                elif node.text == u"False":
                    self.settings[node.tag] = False
                else:
                    self.settings[node.tag] = node.text
        
def SaveConfig(settings, configFile):
    root = etree.Element(u"Config")
    scintilla = etree.SubElement(root, u"Scintilla")
    etree.SubElement(scintilla, u"ShowWhiteSpace").text = str(settings["ShowWhiteSpace"])
    etree.SubElement(scintilla, u"ShowEOL").text = str(settings["ShowEOL"])
    etree.SubElement(scintilla, u"ShowLineNumbers").text = str(settings["ShowLineNumbers"])
    etree.SubElement(scintilla, u"DefaultEOLMode").text = str(settings["DefaultEOLMode"])
    etree.SubElement(scintilla, u"FontSize").text = str(settings["FontSize"]) 
    gui = etree.SubElement(root, u"gui")
    etree.SubElement(gui, u"ShowToolbar").text = str(settings["ShowToolbar"])
    handle = etree.tostring(root, u"utf-8")
    file = open(configFile, u"w")
    file.writelines(handle)
    file.close()